<script lang="ts" setup>
import { onBeforeUnmount, onMounted, ref } from 'vue'
import Login from './Login.vue'
import { useUserStore } from '@/store/modules/employee'

const userStore = useUserStore()
const employeeId = ref<Nullable<number | string>>(0)

onMounted(() => {
  // 记录当前的UserId
  employeeId.value = userStore.getUserInfo?.employeeId
})

onBeforeUnmount(() => {
  if (employeeId.value && employeeId.value !== userStore.getUserInfo.employeeId) {
    // 登录的不是同一个用户，刷新整个页面以便丢弃之前用户的页面状态
    document.location.reload()
  }
})
</script>

<template>
  <transition>
    <div class="fixed z-9999999 h-full w-full bg-[var(--component-background)]">
      <Login session-timeout />
    </div>
  </transition>
</template>
